﻿using UnityEngine;
using System.Collections;

namespace IMIForUnity
{

    public class ImiDevice : IDevice
    {

        public ImiDevice()
        {

        }

        /// <summary>
        /// 打开相应的数据流
        /// </summary>
        /// <param name="frameType"></param>
        /// <param name="imageResolution"></param>
        /// <param name="pixelFormat"></param>
        /// <returns></returns>
        public ErrorCode OpenStream(ImiWrapper.ImiFrameType frameType, ImiResolution.Type imageResolution, ImiWrapper.ImiPixelFormat pixelFormat)
        {
            return ImiWrapper.OpenStream(frameType, imageResolution, pixelFormat);
        }


        /// <summary>
        /// 关闭相应的数据流
        /// </summary>
        /// <param name="frameType"></param>
        /// <returns></returns>
        public ErrorCode CloseStream(ImiWrapper.ImiFrameType frameType)
        {
            return ImiWrapper.CloseStream(frameType);
        }

        /// <summary>
        /// 获得深度图信息
        /// </summary>
        /// <param name="depthData"></param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        public ErrorCode GetDepthData(ushort[] depthData, uint timeOut)
        {
            return ImiWrapper.GetDepthData(depthData, timeOut);
        }

        /// <summary>
        /// 获得深度图信息和骨骼信息
        /// </summary>
        /// <param name="depthData"></param>
        /// <param name="skeletonFrame"></param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        public ErrorCode GetDepthDataAndSkeletonFrame(ushort[] depthData, ref ImiWrapper.ImiSkeletonFrame skeletonFrame, uint timeOut)
        {
            return ImiWrapper.GetDepthDataAndSkeletonFrame(depthData, ref skeletonFrame, timeOut);
        }

        /// <summary>
        /// 获得骨骼信息
        /// </summary>
        /// <param name="skeletonFrame"></param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        public ErrorCode GetSkeletonFrame(ref ImiWrapper.ImiSkeletonFrame skeletonFrame, uint timeOut)
        {
            return ImiWrapper.GetSkeletonFrame(ref skeletonFrame, timeOut);
        }

        /// <summary>
        /// 获得包含玩家id的深度图数据和骨骼信息
        /// </summary>
        /// <param name="depthPlayerData"></param>
        /// <param name="skeletonFrame"></param>
        /// <param name="timeOut"></param>
        /// <returns></returns>
        public ErrorCode GetDepthPlayerDataAndSkeletonFrame(ushort[] depthPlayerData, ref ImiWrapper.ImiSkeletonFrame skeletonFrame, uint timeOut)
        {
            return ImiWrapper.GetDepthPlayerDataAndSkeletonFrame(depthPlayerData, ref skeletonFrame, timeOut);
        }

        /// <summary>
        /// 获得彩色信息
        /// </summary>
        /// <param name="colorData"></param>
        /// <param name="timeOut"></param>
        /// <returns>
        /// 0：成功.
        /// 1：失败.
        /// </returns>
        public ErrorCode GetColorData(byte[] colorData, uint timeOut)
        {
            return ImiWrapper.GetColorData(colorData, timeOut);

        }
        /// <summary>
        /// 是否开启骨架平滑.
        /// </summary>
        /// <param name="isEnable">true:开启 false:关闭</param>
        public void EnableSmoothSkeletonFrame(bool isEnable)
        {
            ImiWrapper.EnableSmoothSkeletonFrame(isEnable);
        }

        /// <summary>
        /// 获得设备状态（连接、未连接）
        /// </summary>
        /// <returns></returns>
        public ImiWrapper.ImiDeviceState GetDeviceState()
        {
            return ImiWrapper.ImiDeviceState.IMI_DEVICE_STATE_CONNECT;
        }
    }
}
